#include "path.h"

// redirect static variable
LPWSTR Path::musicPath;
LPWSTR Path::soundPath;
LPWSTR Path::videoPath;
LPWSTR Path::spritePath;
LPWSTR Path::gamePath;
LPWSTR Path::logFileName;
CString Path::exeFilePath;


Path::Path(void)
{
}


Path::~Path(void)
{
}


void Path::Init() {
  // game Path
  GetModuleFileNameW(NULL, exeFilePath.GetBufferSetLength(250), 250);
  exeFilePath.Truncate(exeFilePath.ReverseFind('\\') + 1 );
  gamePath = (LPWSTR)exeFilePath.GetString();
  // logFileName
  logFileName = new WCHAR[250];
  StringCchCopyW(logFileName, 250, gamePath);
  StringCchCatW(logFileName, 250, LOG_FILE_NAME);
  // Music path
  musicPath = new WCHAR[250];
  StringCchCopyW(musicPath, 250, gamePath);
  StringCchCatW(musicPath, 250, MUSIC_PATH);
  // Sound path
  soundPath = new WCHAR[250];
  StringCchCopyW(soundPath, 250, gamePath);
  StringCchCatW(soundPath, 250, SOUND_PATH);
  // Video path
  videoPath = new WCHAR[250];
  StringCchCopyW(videoPath, 250, gamePath);
  StringCchCatW(videoPath, 250, VIDEO_PATH);
  // Sprite path
  spritePath = new WCHAR[250];
  StringCchCopyW(spritePath, 250, gamePath);
  StringCchCatW(spritePath, 250, SPRITE_PATH);
}


void Path::Release() {
  exeFilePath.ReleaseBuffer(0);
  delete musicPath;
  delete soundPath;
  delete videoPath;
  delete spritePath;
  //delete gamePath;
  delete logFileName;
}


LPWSTR Path::getFullSoundName(LPWSTR shortName) {
  LPWSTR stringTemp = new WCHAR[250];
  StringCchCopy(stringTemp, 250, soundPath);
  StringCchCat(stringTemp, 250, shortName);
  return stringTemp;
}

LPWSTR Path::getFullSpriteName(LPWSTR short_name) {
  LPWSTR stringTemp = new WCHAR[250];
  StringCchCopy(stringTemp, 250, spritePath);
  StringCchCat(stringTemp, 250, short_name);
  return stringTemp;
}